from django.db import models

# Create your models here.


class Account(models.Model):
    user_name = models.CharField(max_length=128)
    money = models.IntegerField(default=1000000)

    def was_money_recently(self):
        return self.money > 0

    was_money_recently.admin_order_field = 'money'
    was_money_recently.boolean = True
    was_money_recently.short_description = "你欠我钱吗?"


class Postion(models.Model):
    account = models.ForeignKey(Account, on_delete=models.CASCADE)
    code = models.CharField(max_length=6)
    number = models.IntegerField(default=0)
    price = models.FloatField(default=0.0)

    def was_number_recently(self):
        return self.number > 0

    was_number_recently.admin_order_field = 'number'
    was_number_recently.boolean = True
    was_number_recently.short_description = "你欠我股票？"

    def was_price_recently(self):
        return self.price > 0

    was_number_recently.admin_order_field = 'price'
    was_number_recently.boolean = True
    was_number_recently.short_description = "你输入的价格符号正确？"


class OrderRecord(models.Model):
    account = models.ForeignKey(Account, on_delete=models.CASCADE)
    operator = models.CharField(max_length=16)
    code = models.CharField(max_length=6)
    number = models.IntegerField(default=0)
    price = models.FloatField(default=0.0)
    date = models.DateTimeField()

    def was_number_recently(self):
        return self.number > 0

    was_number_recently.admin_order_field = 'number'
    was_number_recently.boolean = True
    was_number_recently.short_description = "你欠我股票？"

    def was_price_recently(self):
        return self.price > 0

    was_number_recently.admin_order_field = 'price'
    was_number_recently.boolean = True
    was_number_recently.short_description = "你输入的价格符号正确？"
